package com.Liuhang.Dao;

import com.Liuhang.JDBC.util;
import com.Liuhang.entity.user;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Statement;

public class user_insert extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context = this.getServletContext();
        String name = (String) req.getParameter("username");
        String passwd = (String) req.getParameter("password");
        String sex = (String) req.getParameter("sex");
        String depertment = (String) req.getParameter("dep");
        Integer phone = Integer.valueOf(req.getParameter("phone"));
        Integer money = Integer.valueOf(req.getParameter("money"));
        int dep = Integer.parseInt(depertment);;
        String sql = "INSERT INTO `java01`.`t_emp`(`name`, `sex`, `phone`, `dep_id`, `money` , `passwd`) VALUES ('"+name+"', '"+sex+"', "+phone+", "+depertment+", "+money+","+passwd+")";
        System.out.println(sql);
        try {
            Statement st = util.getStatement();
            st.execute(sql);
            st.close();
        } catch (Exception throwables) {
            throwables.printStackTrace();
        }

    }
}
